package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.AdminMapper;
import com.wanmait.recruit.pojo.Admin;
import com.wanmait.recruit.service.AdminService;
import com.wanmait.recruit.util.PageContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("adminService")
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminMapper adminMapper;
    @Override
    public void insert(Admin object) {

    }

    @Override
    public void delete(Admin object) {

    }

    @Override
    public void update(Admin object) {

    }

    @Override
    public PageInfo<Admin> search(int pageNum, int pageSize) {
        return null;
    }

    @Override
    public Admin login(Admin admin) {
        return adminMapper.login(admin);
    }

    @Override
    public Admin findAdminByName(String username) {
        return adminMapper.findAdminByName(username);
    }

    @Override
    public PageInfo<Admin> findList(String username) {
        int pageNum = PageContext.getPageNum();
        int pageSize = 2;
        PageHelper.startPage(pageNum,pageSize);
        List<Admin> admins = adminMapper.findByName(username);
        PageInfo<Admin> pageInfo = new PageInfo<>(admins,11);
        return pageInfo;
    }



    @Override
    public Admin findById(Integer id) {
        Admin admin = adminMapper.findById(id);
        return admin;
    }

    @Override
    public PageInfo<Admin> findPage(Integer pageNum,String name) {
        int pageSize = 10;
        PageHelper.startPage(pageNum,pageSize);
        List<Admin> admins = adminMapper.findByName(name);
        PageInfo<Admin> pageInfo = new PageInfo<>(admins,11);
        return pageInfo;
    }

    @Override
    public void deleteById(Integer id) {
        adminMapper.deleteById(id);
    }

    @Override
    public void updatePass(Integer id, String passWord) {
        adminMapper.updatePassword(id, passWord);
    }

    @Override
    public Boolean isRename(String name) {
        Admin admin = adminMapper.findAdminByName(name);
        if(admin==null){
            return true;
        }
        else{
            return false;
        }
    }

    @Override
    public void insert(String name, String pass) {
        Admin admin = new Admin();
        admin.setUsername(name);
        admin.setPassword(pass);
        adminMapper.insert(admin);
    }
}
